package jiaerc.moreingredients.block;

import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CropsBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.LootContext;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
//引入自己的类
import jiaerc.moreingredients.MoreIngredientsItems;

import java.util.List;

public class CabbageCropsBlock extends CropsBlock {
    public CabbageCropsBlock() {
        super(Properties.of(Material.PLANT)
                .lightLevel((state) -> 0)
                .noCollission()
                .noOcclusion()
                .randomTicks()
                .instabreak()
                .sound(SoundType.CROP));
    }
    //获取种子
    @MethodsReturnNonnullByDefault
    protected IItemProvider getBaseSeedId() {
        return MoreIngredientsItems.CABBAGE_SEEDS.get();
    }
    //方块可以种在哪里，种在耕地上
    @Override
    protected boolean mayPlaceOn(BlockState floor, IBlockReader world, BlockPos pos){
        return floor.is(Blocks.FARMLAND);
    }
    //作物的最大生长阶段
    @Override
    public int getMaxAge() {
        return 7;
    }
    //配置掉落物，掉落白菜种子和白菜
    @Override
    public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
        List<ItemStack> drops = super.getDrops(state, builder);
        if(getAge(state)>=getMaxAge()){
            drops.add(new ItemStack(MoreIngredientsItems.CABBAGE.get(), 1)); // 成熟时掉落1个大白菜
            drops.add(new ItemStack(MoreIngredientsItems.CABBAGE_SEEDS.get(), 1+RANDOM.nextInt(3)));
            //成熟之后随机掉落种子1-3个
        }else{
            drops.add(new ItemStack(MoreIngredientsItems.CABBAGE_SEEDS.get(),  1));
            //不成熟的时候掉落一个种子
        }
        return drops;
    }
}
